package com.niiwoo.civet.mobile.service.bill.detail;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.account.dto.response.NiiwooBillRespDTO;
import com.niiwoo.civet.account.dto.response.UserBillBaseResponseDTO;
import com.niiwoo.civet.mobile.vo.response.bill.JumpTypeEnum;
import com.niiwoo.civet.mobile.vo.response.bill.UserBillDetailResponse;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorSaleDetailResponseDTO;
import com.niiwoo.civet.trade.service.creditor.CreditorRightsDubboService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 转让账单说情
 * Created by Yijian on 2018/11/8.
 */
@Service
public class TransferBillDetailStrategyImpl implements BillDetailStrategy {

    @Reference(version = "1.0.0")
    private CreditorRightsDubboService creditorRightsDubboService;

    @Override
    public String build(UserBillBaseResponseDTO userBillBase, List<NiiwooBillRespDTO> userBillFlowList, UserBillDetailResponse response) {

        // 根据债转ID和用户ID取出债权转让记录期限利率
        CreditorSaleDetailResponseDTO creditorSaleDetail = creditorRightsDubboService.getCreditorSaleDetail(Long.valueOf(response.getOrderId()), userBillBase.getUserId());

        if(Objects.nonNull(creditorSaleDetail)) {
            UserBillDetailResponse.SpecialItem specialItem = response.new SpecialItem();
            specialItem.setName("转让记录");
            specialItem.setContent("转让-"+creditorSaleDetail.getRemainingDeadlineMonth() + "个月" + " " + creditorSaleDetail.getBorrowRateDesc() + "%");
            specialItem.setIsNeedJump(Boolean.TRUE);
            specialItem.setJumpType(JumpTypeEnum.INVEST_ORDER.getCode());
            specialItem.setJumpParamOne(creditorSaleDetail.getInvestOrderId().toString());//转让标的原始投资订单id
            response.getSpecialItems().add(specialItem);
        }

        return JSON.toJSONString(response);
    }
}
